<?php
require_once("DButil.php");

//建议把查询的列名详细的写出来，不建议使用 *
// $sql="select * from product";
$sql="select p_id,p_name,p_price,p_unit,p_image_url from product";

$conn=getConn();
$result=mysqli_query($conn,$sql);
// var_dump($result);

// 有结果则处理结果中数据
if($result){
    $num=mysqli_num_rows($result);
    echo "总共有{$num}条数据<br>";
    echo "<table border='1' cellspacing='0' cellpadding='5' >";
    echo "<thead>
            <td>编号</td>
            <td>名称</td>
            <td>价格</td>
            <td>单位</td>
            <td>图片地址</td>
        </thead>";
    echo "<tbody align='center'>";
    for($m=0;$m<$num;$m++){
        echo "<tr>";
        $row= mysqli_fetch_assoc($result);
        foreach($row as $key=> $value){
            if($key=="p_image_url"){
                echo "<td><img style='width:100px;' src='{$value}'></td>";
            }else{
                echo "<td>{$value}</td>";
            }
        }
        
        echo "</tr>";
        
    }
    echo "</tbody>";
    echo "</table>";
}

mysqli_close($conn);


?>